package com.i2bt.adapter;

import com.i2bt.R;
import com.i2bt.app.share.ShareChangeShareActivity;

import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

public class changeShareAdapter extends BaseAdapter {
	private ShareChangeShareActivity act;

	public changeShareAdapter(ShareChangeShareActivity act) {
		this.act = act;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.act.has.length;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(this.act).inflate(
					R.layout.item_change_my_share, null, false);
			holder = new ViewHolder();
			holder.checkbox = (CheckBox) convertView
					.findViewById(R.id.share_changeMyShare_CheckBox);
			this.act.check[position] = holder.checkbox;
			this.act.check[position].setChecked(act.has[position]);

			holder.friendName = (TextView) convertView
					.findViewById(R.id.share_changeMyShare_friendName);
			holder.friendName.setText(this.act.friendList.get(position));

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
			holder.checkbox = (CheckBox) convertView
					.findViewById(R.id.share_changeMyShare_CheckBox);
			this.act.check[position] = holder.checkbox;
			this.act.check[position].setChecked(act.has[position]);
			holder.friendName = (TextView) convertView
					.findViewById(R.id.share_changeMyShare_friendName);
			holder.friendName.setText(this.act.friendList.get(position));
		}
		this.act.check[position].setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				act.has[position] = act.check[position].isChecked();
			}
		});
		return convertView;
	}

	private class ViewHolder {
		CheckBox checkbox;
		TextView friendName;
	}
}
